﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace EGS.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ClockinController : ControllerBase
    {
        private readonly EGSDbContext db;
        public ClockinController(EGSDbContext context)
        {
            db = context;
        }


        public List<EGS_Clockin> GetAll()
        {
            return db.Clockins.ToList();
        }



        [HttpGet("{id}")]

        public EGS_Clockin? GetEGS_ClockinById(Guid id)
        {
            EGS_Clockin? clockin = new EGS_Clockin();
            clockin = db.Clockins.Where(u => u.ID == id).FirstOrDefault();
            return clockin;
        }

        [HttpPost]
        public Result AddClockins([FromBody] EGS_Clockin clockin)
        {
            Result result = new Result();
            db.Clockins.Add(clockin);
            result.Data = db.SaveChanges();
            return result;
        }

        [HttpPost]
        public Result AddClockin([FromBody] EGS_Clockin account)
        {
            Result result = new Result();
            EGS_Clockin clockins = null;
            db.Clockins.Add(clockins);
            result.Data = db.SaveChanges();
            return result;
        }
        
        [HttpPut]
        public Result UpClockins([FromBody] EGS_Clockin clockin)
        {
            Result result = new Result();
            db.Clockins.Update(clockin);
            result.Data = db.SaveChanges();
            return result;
        }

        [HttpGet]
        public Result Get(Guid id)
        {
            Result result = new Result();
            result.Data = db.Clockins.Where(w => w.ID == id).FirstOrDefault();
            return result;
        }
        //        [HttpGet("{id}")]
        //public EGS_Clockin? GetEGS_ClockinById(Guid id)
        //{
        //    EGS_Clockin? account = new EGS_Clockin();
        //    account = db.Clockins.Where(a => a.ID == id).FirstOrDefault();
        //    return account;
        //}
    

        //[HttpPut]
        //public bool Update(EGS_Clockin clockin)
        //{
        //    db.Clockins.Update(clockin);
        //    int result = db.SaveChanges();
        //    return result > 0 ? true : false;
        //}



    }
}
